package com.azier.datasource;

import com.azier.influxdb.mapper.InfluxDBBaseMapper;
import com.azier.influxdb.util.InfluxDBConnectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
/**
 * 缓存配置
 *
 * @author 罗军
 *         <p>
 *         Date: 2019-6-3 9:58.
 *         </p>
 */
@Configuration
public class InfluxDBDataSource {

    @Value("${influxDB.host:http://localhost}")
    private String              hostName;

    @Value("${influxDB.port:8086}")
    private int                 port;

    @Value("${influxDB.database:seem}")
    private String              database;

    @Value("${influxDB.username:admin}")
    private String              username;

    @Value("${influxDB.password:admin}")
    private String              password;

    @Value("${influxDB.retentionPolicy:autogen}")
    private String              retentionPolicy;

    @Value("${influxDB.enableBatch:true}")
    private boolean              enableBatch;

    @Value("${influxDB.maxPoints:1000}")
    private int              maxPoints;

    @Value("${influxDB.maxTime:5000}")
    private int              maxTime;

    @Value("${influxDB.connectTimeOut:20}")
    private int              connectTimeOut;

    @Value("${influxDB.readTimeOut:300}")
    private int              readTimeOut;

    @Value("${influxDB.writeTimeOut:30}")
    private int              writeTimeOut;
    @Bean
    public InfluxDBConnectionUtil influxDBConnectionUtil() {
        String openUrl = hostName+":"+port;
        return new InfluxDBConnectionUtil(username,password,openUrl,database,retentionPolicy,
                enableBatch,maxPoints,maxTime,
                connectTimeOut,readTimeOut,writeTimeOut);
    }
    @Bean
    public InfluxDBBaseMapper influxDBBaseMapper() {
        return new InfluxDBBaseMapper(influxDBConnectionUtil().getInfluxDB());
    }
}
